package com.packet.controller;

import com.packet.pojo.Trip;
import com.packet.service.FinanceCorrectTripService;
import com.packet.service.FinanceQueryService;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static javax.swing.text.html.FormSubmitEvent.MethodType.POST;
import static org.apache.poi.sl.usermodel.PresetColor.Control;
import static org.aspectj.lang.reflect.DeclareAnnotation.Kind.Method;

/**
 * @className:FinanceQueryController
 * @Author:wallet_packet Date:2023-12-07 16:51
 * @Describe:
 */
@Controller
public class FinanceQueryController {

    @Autowired
    FinanceQueryService financeQueryService;

    @Autowired
    FinanceCorrectTripService financeCorrectTripService;
    @RequestMapping("/finance/queryNoCorrect")
    public String queryNoCorrect(Model model){
        List<Trip> trips = financeQueryService.selectTripNoCorrect();
        model.addAttribute("trips",trips);
        //List<Staff> staffs = financeCorrectTripService.selectStaff();
        //model.addAttribute("staffs",staffs);
        return "/finance/list";
    }
    @RequestMapping("/finance/queryAll")
    public String queryAll(Model model) {
        List<Trip> trips = financeQueryService.selectTripAll();
        model.addAttribute("trips",trips);
        return "/finance/query";
    }

    /**
     * 先跳转到controller，查询全部返回界面
     * 界面筛选内容传回controller，再通过controller，显示对应要求
     * 传回去
     * @return
     */

    @RequestMapping("/finance/queryByChoice")
    public String queryByChoice(@RequestBody Map<String,Object> map, Model model
                                 ){

        HashMap<String, Object> map1 = new HashMap<>();
        Map<String, Object> handleMap = financeQueryService.handleChoice(map);
        int count = financeQueryService.selectCount();
        List<Trip> trips = financeQueryService.selectTripByChoice(handleMap);
        model.addAttribute("trips",trips);
        return "/finance/query::trips";
    }

    @RequestMapping("/finance/queryAll/staff")
    @ResponseBody
    public List<Trip> queryAllStaff() {
        List<Trip> trips = financeQueryService.selectTripNoCorrect();
        return trips;
    }
    

}
